<template>
  <el-container>

    <el-row>
      <el-button
        icon="fa fa-fw fa-refresh"
        size="mini"
        type="info"
        @click="handleRefresh">
      </el-button>
    </el-row>

    <el-table
      @selection-change="handleSelectionChange"
      :data="tableData"
      tooltip-effect="dark"
      border
      :default-sort="{prop: 'date', order: 'descending'}"
      :row-class-name="tableRowClassName"
    >

      <el-table-column
        prop="runnerName"
        label="插件名称">
      </el-table-column>

      <el-table-column
        prop="runnerName"
        label="介绍">
      </el-table-column>


      <el-table-column
        prop="money"
        label="价格">
        <template slot-scope="scope">
          <i class="fa fa-fw fa-rmb"></i>
          <span style="margin-left: 10px">{{ scope.row.money}}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="runnerName"
        label="下载统计">
      </el-table-column>

      <el-table-column
        prop="runnerName"
        label="版本">
      </el-table-column>

      <el-table-column
        prop="price"
        label="状态">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.price">
          </el-switch>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        width="120">
        <template slot-scope="scope">
          <el-button
            circle
            icon="fa fa-fw fa-check"
            size="mini"
            type="success"
            title="同意"
            @click="handleWithdrawAcceptItem(scope.$index, scope.row)">
          </el-button>

          <el-button
            circle
            icon="fa fa-fw fa-remove"
            size="mini"
            type="danger"
            title="拒绝"
            @click="handleWithdrawRejectItem(scope.$index, scope.row)">
          </el-button>

        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.currentPage"
      :page-sizes="pagination.pageSizes"
      :page-size="pagination.pageSize"
      :total="pagination.total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

  </el-container>
</template>

<script>
  export default {
    mounted: function () {
      // this.getData();
    },
    methods: {
      /**
       * 数据请求
       * */
      getData: function () {
        let _this = this;
        this.api.getRefundPromiseMoneyTabulation({
          page: this.pagination.currentPage,
          paginate: this.pagination.pageSize,
        }).then(function (res) {
          if (res.code == 1) {
            _this.tableData = res.data.data;
            _this.pagination.total = res.data.total;
          }
        }).catch(function (res) {
          throw new Error(res);
        });
      },
      /**
       * 同意申请
       * @param index
       * @param row
       */
      withdrawAccept({id: id}) {
        let _this = this;
        _this.api.runnerRefundPromiseMoneyAccept({rid: id}).then(function (res) {
          if (res.code == 1) {
            _this.getData();
            _this.$message({
              showClose: true,
              message: res.msg,
              type: 'success'
            });
          } else {
            _this.$message({
              showClose: true,
              message: res.msg,
              type: 'warning'
            });
          }
        }).catch(function (error) {
          throw new Error(error);
        });
      },
      /**
       * 同意申请
       */
      handleWithdrawAcceptItem(index, row) {
        let _this = this;
        let _id = row.id;
        this.$confirm('此操作将同意该申请, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          _this.withdrawAccept({id: _id});
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消该操作'
          })
        })
      },
      /**
       * 拒绝申请
       * @param index
       * @param row
       */
      handleWithdrawRejectItem(index, row) {
        let _this = this;
        let _id = row.id;
        this.$confirm('此操作将拒绝该申请, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          _this.api.runnerRefundPromiseMoneyReject({rid: _id}).then(function (res) {
            if (res.code == 1) {
              _this.getData();
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'success'
              });
            } else {
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'warning'
              });
            }
          }).catch(function (error) {
            throw new Error(error);
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          });
        });
      },
      /**
       * 分页数改变
       */
      handleSizeChange: function (pageSize) {
        this.pagination.pageSize = pageSize;
        this.getData();
      },
      /**
       * 当前页面改变
       * @param currentPage
       */
      handleCurrentChange: function (currentPage) {
        this.pagination.currentPage = currentPage;
        this.getData();
      },
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row'
        } else if (rowIndex === 3) {
          return 'success-row'
        }
        return ''
      },
      /**
       * 数据刷新
       */
      handleRefresh: function () {
        this.getData();
        this.$message({
          showClose: true,
          message: '刷新成功',
          type: 'success'
        });
      },
      /**
       * 表格选中状态记录
       * @param val
       */
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
    },
    data() {
      return {
        tableData: [
          {
            "id": '1',                //类型：Number  必有字段  备注：配送员id
            "name": '',                //类型：String  必有字段  备注：银行卡姓名
            "runnerName": '',                //类型：String  必有字段  备注：配送员姓名
            "money": '',                //类型：String  必有字段  备注：账户余额
            "price": '',                //类型：String  必有字段  备注：保证金金额
            "bank_number": '',                //类型：String  必有字段  备注：银行卡号
            "title": ''                //类型：String  必有字段  备注：开户行
          },
        ],
        multipleSelection: [],
        pagination: {
          total: 5,
          currentPage: 1,
          pageSize: 10,
          pageSizes: [5, 10, 20, 25, 30, 50, 100],
        },
      }
    },
  }
</script>

<style scoped>
  .el-container {
    display: block;
  }

  .el-table, .el-row {
    width: 98% !important;
    margin: 15px auto;
  }

  .el-pagination {
    text-align: center;
    margin: 15px 0;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  .logo-img {
    width: 40px;
    height: 40px;
  }

  .el-date-picker {
    top: -3px;
    margin: 0 0 0 15px;
  }
</style>
